local hx__yunmie = fk.CreateSkill{
  name = "hx__yunmie",

  tags = {},
}

hx__yunmie:addEffect("active",{
  name = "hx__yunmie",
  prompt = "hx__yunmie_prompt",
  can_use = function (self, player)
    return player:usedSkillTimes(hx__yunmie.name) == 0 and player:getMark("@hx__yunmie_record") > 0
  end,
  target_num = 1,
  target_filter = function (self, player, to_select, selected, selected_cards)
    return #selected == 0
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  on_use = function (self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    room:damage{
      to = target,
      damage = player:getMark("@hx__yunmie_record"),
      from = player,
      skillName = hx__yunmie.name
    }
  end,
})


hx__yunmie:addEffect(fk.Damage,{
  name = "hx__yunmie",
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(hx__yunmie.name) and target and target == player
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player,"@hx__yunmie_record",data.damage)
  end,
})

hx__yunmie:addEffect(fk.DamageCaused,{
  name = "hx__yunmie",
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(hx__yunmie.name) and target and target == player and data.card and data.card.trueName == "slash"
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player,"hx__yunmie_damage",data.damage)
      local suc,dat = room:askToUseActiveSkill(player,{ skill_name = "#hx__yunmie__active" , cancelable = false, prompt = "hx__yunmie__changedamage" })
      if suc and dat then
        data:changeDamage(dat.interaction - data.damage)
      end
  end,
})

hx__yunmie:addEffect(fk.CardUsing,{
  anim_type = "offensive",
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(hx__yunmie.name) and target and target == player and data.card.trueName == "slash"
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:broadcastPlaySound("./packages/huixiangkill/audio/skill/hx__yunmie_slash")
    data.additionalDamage = (data.additionalDamage or 0) + 2
    for _, v in ipairs(data.tos) do
      if v.hp > 10 then
        data.additionalDamage = (data.additionalDamage or 0) + 999
        break
      end
    end
  end,
})

return hx__yunmie